function login(user,pass){
	var params={
			"username":user,
			"password":pass
	};
	if(user.length==0||pass.length==0){
		alert("用户名或密码不能为空")
	}else{
	$.ajax({
        "contentType": "application/json; charset=utf-8",
        "type": "POST",
        "url": "login",
        "data": JSON.stringify(params),   
        "success": function (data,textStatus) {
            console.log(data);
            if(data){
            	location="welcome.html"
            }else{
            	alert("用户名或密码错误")
            }
            //$("#p").text("welcome,"+data);
            //alert(data[0]);
        }
    });
	//return false;
	}
}

function isLogin(){
	$.ajax({
        "contentType": "application/json; charset=utf-8",
        "type": "GET",
        "url": "checkLogin",
        "data": JSON.stringify(params),   
        "success": function (data,textStatus) {
            console.log(data);
            if(!data){
            	location="index.html"
            }
            //$("#p").text("welcome,"+data);
            //alert(data[0]);
        }
    });
}
function checkLogin(){
	$.ajax({
	    "contentType": "application/json; charset=utf-8",
	    "type": "GET",
	    "url": "checkLogin",
	    "success": function (data,textStatus) {
	    	console.log(data.username)
	        if(!data.regiest){
	        	location="index.html";
	        }
	        else{
	        	sessionStorage.myUsername=data.username;
	        	sessionStorage.myUid=data.uid;
	        	sessionStorage.myDescription=data.description;
	        	sessionStorage.myRank=data.rank;
	        	sessionStorage.cate=0;
	        	sessionStorage.ques=0;
	        	//console.log(data);
	        	show();
	        }
	    }
	});
}


$(document).ready(function(){
	$("#loginButton").click(function(){
		login($("#username").val(),$("#password").val()	);	
	});
});
